package com.aaa.controller.sas;


import cn.hutool.core.util.ObjectUtil;
import com.aaa.aspect.LogMonitor;
import com.aaa.controller.BaseController;
import com.aaa.entity.PageSortEntity;
import com.aaa.entity.Result;
import com.aaa.entity.sas.QuestionSas;
import com.aaa.service.sas.QuestionSasService;
import com.github.pagehelper.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * @author ：马明钢
 * @date ：Created in 2022/8/29 15:23
 * @description：
 * @modified By：
 * @version:
 */
@Controller
@RequestMapping("/SAS")
public class QuestionSasController extends BaseController {
    @Autowired
    QuestionSasService questionSasService;


    @ResponseBody
    @RequestMapping("/queryAll.do")
    public Result queryAll(PageSortEntity page, QuestionSas questionSas){
        Page pageResult = (Page) questionSasService.queryAll(page, questionSas);
        return success(pageResult.getResult(),pageResult.getTotal());
    }


    @LogMonitor
    @ResponseBody
    @RequestMapping("/insert.do")
    public Result insert( QuestionSas questionSas){
        boolean b = questionSasService.insert(questionSas);
        if (b){
           return success();
        }
        return fail();
    }

    @LogMonitor
    @ResponseBody
    @RequestMapping("/delete.do")
    public Result delete(String id){
        boolean b = questionSasService.delete(id);
        if (b){
           return success();
        }
        return fail();
    }

    @LogMonitor
    @ResponseBody
    @RequestMapping("/update.do")
    public Result update(QuestionSas questionSas){
        boolean update = questionSasService.update(questionSas);
        if (update){
            return success();
        }
        return fail();
    }


    @ResponseBody
    @RequestMapping("/repetitionName.do")
    public Result repetitionName(QuestionSas ts){
        if (ObjectUtil.isEmpty(ts.getQuestion())){
            return fail("不能为空");
        }else {
            boolean b = questionSasService.repetitionName(ts);
            if (b){
                return success("题目名可用");
            }
            return  fail("题目重复不可用");
        }
    }

    @ResponseBody
    @RequestMapping("/repetitionID.do")
    public Result repetitionID(QuestionSas ts){
        if (ObjectUtil.isEmpty(ts.getId())){
            return fail("不能为空");
        }else {
            boolean b = questionSasService.repetitionID(ts);
            if (b){
                return success("ID可用");
            }
            return  fail("ID重复不可用");
        }
        }
}
